package com.memorywords.mapper;

import com.github.pagehelper.Page;
import com.memorywords.pojo.Word;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WordMapper {

    @Select("select * from word where word_id >= #{progress} order by word_id asc limit 10")
    List<Word> getNew(int progress);

    @Insert("insert into user_word(user_id, word_id, update_time) values (#{userId}, #{wordId}, now())")
    void mark(int userId, int wordId);

    @Select("select word.* from word join user_word on word.word_id = user_word.word_id where user_word.user_id=#{userId}")
    List<Word> getOld(int userId);

    @Delete("delete from user_word where user_id=#{userId} and word_id=#{wordId}")
    void remove(int userId, int wordId);

    Page<Word> getAll(int userId, int pageNum, int pageSize);




    ///////
    @Select("select * from cet46 ")
    List<Word> getWord();

    @Insert("insert into vocabulary (word_id, word, chinese, sent) values (#{id}, #{word}, #{chinese}, #{sent})")
    void insertVocabulary(int id, String word, String chinese, String sent);

    @Insert("insert into book_word (book_id, word_id) values (#{i}, #{wordId})")
    void insertBookWord(int i, int wordId);


    @Select("select * from vocabulary where word=#{word} limit 1")
    Word findWord(String word, String chinese, String sent);
}
